<#include "../base.ftl"/>
<#macro cssfile>
</#macro>

<#macro scriptfile>
</#macro>

<#macro breadcrumb>
    <ul class="breadcrumb">
     <#include "../crumb.ftl"/>
     <li class="active">船舶航次</li>
    </ul>
</#macro>
<#macro title>
广大物流云平台
</#macro>

<#macro jsscript>
  var setting = {
        async: {
            enable: true,
            url: '${request.contextPath}/admin/crewTree.action',
            datatype : 'json',
            autoParam:["id","name","pId"]
        },
        data: {
            simpleData: {
                   enable: true
            }
        },
        callback:{
         onNodeCreated  : zTreeonNodeCreated,
            onClick:zTreeClick
        }
        
    };
    function fillCategoryId(params,postdata){
       var treeObj=$.fn.zTree.getZTreeObj("categoryTree");
       var nodes=  treeObj.getSelectedNodes();
       var add_data=new Object();
       var a=nodes[0].id;
       a=a.replace("B","");
       add_data["crewId"]=a;
       add_data["beanName"] = "tsm.TsmCrewCer";
       return add_data;
   }
   function zTreeonNodeCreated(event, treeId, treeNode){
        var treeObj = $.fn.zTree.getZTreeObj(treeId);
        //treeObj.expandNode(treeNode, true, true, true);
        var list = treeObj.getNodeByParam("level",'0');
        treeObj.expandNode(list, true, false, true); 

        
    }
    
    function zTreeClick(event,treeId,treeNode){
    var a=treeNode.id;
      a=a.replace("B","");
    //alert(a);
        jQuery("#gridTable").jqGrid('setGridParam',{
            url : "${request.contextPath}/list!list.action?crewId="+a,
            page : 1 
        });
        jQuery("#gridTable").trigger('reloadGrid');
    }

    jQuery(document).ready(function(){
        $.fn.zTree.init($("#categoryTree"), setting);
       
    });
    
$(function(){
    $("#gridTable").jqGrid({
    //list表格获取地址
        url:'${request.contextPath}/list!list.action',
        datatype: "json",
        mtype:"POST",
        height: 200,
        colNames:['证书编号','船员编号','证书代码','证书名','开始日期','结束日期','备注','状态','创建人','创建日期','最后修改人','最后修改时间','文件地址'],
        colModel:[
                    {name:'cerId',jsonmap:'CER_ID',editable:true,hidden:true,editrules:{edithidden:true,required:false}},
                    {name:'crewId',jsonmap:'CREW_ID',editable:false,editrules:{edithidden:true,required:false},hidden:true},
                    {name:'cerCode',jsonmap:'CER_CODE',editable:true,editrules:{required:true,number:true}},
                    
                    {name:'cerName',jsonmap:'CER_NAME',editable:true,editrules:{required:true}},
                    
                        {name:'startDate', classes:'qqqqq',jsonmap:'START_DATE',editable:true,editrules:{required:true,data:true},
                           editoptions :  {dataInit: function(element) {
                            $(element).datepicker({
                            changeMonth : true,
                            changeYear : true,
                            dateFormat : 'yy-mm-dd',
                            onClose: function(selectedDate){
                            var   today=new   Date(selectedDate);       
                            var   yesterday_milliseconds=today.getTime()+1000*60*60*24;      
                            var   yesterday=new   Date();      
                            yesterday.setTime(yesterday_milliseconds);      
           
                            var strYear=yesterday.getFullYear();   
                            var strDay=yesterday.getDate();   
                            var strMonth=yesterday.getMonth()+1;   
                            if(strMonth<10)   
                                        {   
                                strMonth="0"+strMonth;   
                                     }   
                              var strYesterday=strYear+"-"+strMonth+"-"+strDay;   
                             
                            $("#endDate").datepicker("option","minDate",strYesterday);
                            }
                            });
                        }}               
                    },
                    {name:'endDate',classes:'aaaaa',jsonmap:'END_DATE',editable:true,editrules:{required:true},
                              editoptions :  {dataInit: function(element) {
                            $(element).datepicker({
                            changeMonth : true,
                            changeYear : true,
                            dateFormat : 'yy-mm-dd',
                            onClose: function(selectedDate){
                            var   today=new   Date(selectedDate);       
                            var   yesterday_milliseconds=today.getTime()+1000*60*60*24;      
                            var   yesterday=new   Date();      
                            yesterday.setTime(yesterday_milliseconds);      
           
                            var strYear=yesterday.getFullYear();   
                            var strDay=yesterday.getDate();   
                            var strMonth=yesterday.getMonth()+1;   
                            if(strMonth<10)   
                                        {   
                                strMonth="0"+strMonth;   
                                     }   
                              var strYesterday=strYear+"-"+strMonth+"-"+strDay;   
                            $("#startDate").datepicker("option","maxDate",strYesterday);
                            }
                            });
                        }}       
                    },
                    {name:'remark',jsonmap:'REMARK',editable:true,editrules:{edithidden:true,required:true},hidden:true},
                    {name:'status',jsonmap:'STATUS',editable:false,edittype:'select',align:'center',editrules:{required:true},editoptions:{value:{0:'有效',1:'无效'}},hidden:true},
                    {name:'createdBy',jsonmap:'CREATED_BY',editable:false,editrules:{required:true},hidden:true},
                    {name:'createdDate',jsonmap:'CREATED_DATE',editable:false,hidden:true,editrules:{required:true},
                        editoptions :  {dataInit: function(element) {
                            $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                        }}       
                    },
                    {name:'lastUpdBy',jsonmap:'LAST_UPD_BY',editable:false,editrules:{required:true},hidden:true},
                    {name:'lastUpdDate',jsonmap:'LAST_UPD_DATE',editable:false,hidden:true,editrules:{required:true},
                      editoptions :  {dataInit: function(element) {
                            $(element).datepicker({changeMonth : true,changeYear : true,dateFormat : 'yy-mm-dd'});
                        }}  
                    },
                    {name:'fileUrl',jsonmap:'FILE_URL',editable:false,hidden:true,editrules:{required:true}},
                    //{name:'gu',index:'index1',label:'更新',align:'center',}
                    
                    
                    ],
        sortname : 'CER_ID',
        sortorder : 'ASC',
        viewrecords : true,
        gridview : true,
        rownumbers : true,
        autowidth : true,
        editurl: '${request.contextPath}/operator.action',
        rowNum : 20,
        rowList : [10,20,30],
             
        jsonReader : {
            page : "page.pageNo", //固定名称
            total : "page.totalPages", //固定名称
            records : "page.totalCount", //固定名称
            root : "page.result", //固定名称
            repeatitems : false, //固定
            id : 'CER_ID'
        },  
        prmNames : {
            rows : "page.pageSize",
            page : "page.pageNo",
            sort : "page.orderBy",
            order : "page.order"
        },
        loadBeforeSend : function(xhr,settings){
            //设置访问的list标签
            settings.data=settings.data+ "&gridKey=/list#TsmCrewCer";
            return true;
        },
        pager : "#gridPager",
        caption : "船员证书列表"
        }).navGrid('#gridPager', {
                edit : true,
                add : true, 
                del : true,
                search : true
        }, {  
                //edit
           //bSubmit: "Submit",
           //function(){
             // $("#FrmGrid_gridTable").attr("action","${request.contextPath}/admin/getShipManagementList!uploadFile.action");
              //$("#FrmGrid_gridTable").attr("method","post");
               //$("#FrmGrid_gridTable").attr("onsubmit","return:true");
              //$("#FrmGrid_gridTable").attr("enctype","multipart/form-data");
              //$("#FrmGrid_gridTable").submit();
            
            //return false;
           //},
           //reloadAfterSubmit : true, 
           //beforeSubmit:true,
           reloadAfterSubmit : true, 
           closeAfterEdit : true,  //修改完毕后关闭
           afterComplete : opertaionPrompt, //更新结束后提示信息
           onclickSubmit:fillCategoryId
        }, {
                //add
           reloadAfterSubmit : true,
           closeAfterAdd : true, //新增完毕后关闭
           afterComplete : opertaionPrompt,
           onclickSubmit: fillCategoryId
       },{  
       //del
           reloadAfterSubmit : true, 
           closeAfterEdit : true,  //修改完毕后关闭
           afterComplete : opertaionPrompt, //更新结束后提示信息
           onclickSubmit: fillCategoryId      
       
       }).navButtonAdd("#gridPager",{
    	   caption:"上传",
    	   buttonicon:"ui-icon-add",
    	   onClickButton: function(){
    	  
    	      var consoleDialog=$("#fileUploadDialog");
    	      consoleDialog.dialog('option',"title","船员证书文件上传").dialog("open");
    	      
       }
    	   
       });
    
    
    $("#fileUploadDialog").dialog({
		  autoOpen:false,
		  model:true,
		  resizable: true,      
	      width: 480,  
	      open: function(){
    	$('#file_upload').uploadify({
    	    'buttonText'    :   '选择文件',  //上传文件按钮名称
    	    'fileObjName' : 'file_upload',
    	    'multi'         :   false,  //每次是否只能上传一个文件
    	    'swf'      : '${request.contextPath}/libs/uploadify/css/uploadify.swf',
    	    'uploader' :  '${request.contextPath}/file/upfile.action;jsessionid=<%=session.getId()%>',//文件上窜URL，固定URL
    	    'auto'          :   true,  //文件是否自动上传
    	    'uploadLimit': 9,//上传文件最大个数
    	    'onUploadSuccess' : function(file, data, response) {//文件上传成功后回调
    	       
    	    
    	        $.each(JSON.parse(data),function(k,v){
    	            
    	            alert(k+"----"+v);
    	        });
    	        
    	    }
    	});
    }
	      
	  });
   });
    
	  
	  
	  
 


</#macro>
<#macro main>
	<div class="leftMaindiv">
	  <div id="treediv" class="ui-widget-content ui-corner-all">
	           <ul id="categoryTree" class="ztree"></ul>
	  </div>
  	</div>
  	<div class="rightdetaildiv">
           <table id="gridTable"></table>
           <div id="gridPager"></div>
  	</div>
  	<div id="fileUploadDialog" style="visibility:hidden">
      <input id="file_upload" name="file_upload" type="file"  multiple="true"/>
  </div>
</#macro>

